package net.qhzw.vip.qiyu.controller;

import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import net.qhzw.vip.qiyu.model.LoginResult;
import net.qhzw.vip.qiyu.model.WxLoginInfo;
import net.qhzw.vip.qiyu.result.JsonResult;
import net.qhzw.vip.qiyu.service.WxAuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 微信鉴权服务
 */
@RestController
@RequestMapping("/wx/auth")
@Slf4j
public class WxAuthController {

    @Autowired
    private WxAuthService wxAuthService;


    @ApiOperation(value = "微信登录")
    @PostMapping("loginByWeixin")
    public JsonResult<LoginResult> loginByWeixin(@RequestBody WxLoginInfo wxLoginInfo,
                                                 HttpServletRequest request) {
        //log.info("【微信登录】,请求参数,body:{}", wxLoginInfo);
        LoginResult loginUser = wxAuthService.loginByWeixin(wxLoginInfo, request);
        //log.info("【微信登录成功】,响应结果:{}", JSONObject.toJSONString(loginUser));
        return JsonResult.ok(loginUser);
    }


}
